{% extends 'base.html' %}

{% block title %}{{ _('Manage Categories') }}{% endblock %}

{% block content %}
    <div class="page-header">
        <h1>{{ _('Categories') }}
            <small class="text-muted">{{ categories | length }}</small>
            <span class="float-right"><a href="{{ url_for('.new_category') }}" class="btn btn-primary btn sm">{{ _('New Category') }}</a></span>
        </h1>
    </div>
    {% if categories %}
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>{{ _('No.') }}</th>
                    <th>{{ _('Name') }}</th>
                    <th>{{ _('Posts') }}</th>
                    <th>{{ _('Actions') }}</th>
                </tr>
            </thead>
            {% for category in categories %}
                <tr>
                    <td>{{ loop.index }}</td>
                    <td><a href="{{ url_for('blog.show_category', category_id=category.id) }}">{{ category.name }}</a></td>
                    <td>{{ category.posts | length }}</td>
                    <td>
                        {% if category.id != 1 %}
                            <a href="{{ url_for('.edit_category', category_id=category.id) }}" class="btn btn-info btn-sm">{{ _('Edit') }}</a>
                            <form class="inline" action="{{ url_for('.delete_category', category_id=category.id) }}" method="post">
                                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                                <button class="btn btn-danger btn-sm" type="submit" onclick="return confirm('{{ _('Are you sure?') }}');">{{ _('Delete') }}</button>
                            </form>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        </table>
        <p class="text-muted">{{ _('Tips: Deleting a category does not delete the article under that category.') }}
            {{ _('The articles under this category will be moved to the default category.') }}</p>
     {% else %}
        <div class="tip"><h5>{{ _('No Categories.') }}</h5></div>
    {% endif %}
{% endblock %}